package cn.simon.util;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

public class SqlSessionUtil {
    private static SqlSession sqlSession = null;
    public static SqlSession getSqlSession(){
        //读取配置文件
        InputStream is = SqlSessionUtil.class.getClassLoader().getResourceAsStream("mybatis-config.xml");
        if(sqlSession == null){
            SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
            sqlSession = factory.openSession();
        }
        return sqlSession;
    }
}
